<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="会员昵称" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入会员昵称"
          clearable
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <el-option 
              v-for="dict in dict.type.adv_order_status"
              :label="dict.label" 
              :value="dict.value"
              :key="dict.value"/>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
        />
      </el-form-item> -->
      <el-form-item label="订单号" prop="ordersno">
        <el-input
          v-model="queryParams.ordersno"
          placeholder="请输入订单号"
          clearable
        />
      </el-form-item>
      <!-- <el-form-item label="订单数量" prop="ordersNum">
        <el-select v-model="queryParams.ordersNum" placeholder="订单数量" clearable>
          <el-option 
              v-for="item in 100"
              :label="item" 
              :value="item"
              :key="item"/>
        </el-select>
      </el-form-item> -->
      <el-form-item label="订单日期" prop="advOrdersdate">
        <el-date-picker
          v-model="queryParams.advOrdersdate"
          type="date"
          placeholder="请选择订单日期"
          style="width: 180px"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

     <el-row :gutter="10" class="mb8"> 
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:role:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:role:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-tooltip placement="top">
      <div slot="content">点击任意一行即可查看订单明细记录</div>
    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange" @row-click="showTab" :row-class-name="rowClassName">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单Id" align="center" prop="advOrdersId" v-if="false"/>
      <el-table-column label="订单号" align="center" prop="ordersno" />
      <el-table-column label="订单日期" align="center" prop="advOrdersdate" />
      <el-table-column label="会员昵称" align="center" prop="memberName" />
      <el-table-column label="会员账号" align="center" prop="memberAccount" />
      <!-- <el-table-column label="产品名称" align="center" prop="productName" /> -->
      <el-table-column label="订单总金额" align="center" prop="ordersamount" />
      <el-table-column label="物流信息" align="center"  prop="delivesno"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.adv_order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-finance"
            @click="handleRefund(scope.row)"
            v-hasPermi="['system:role:edit']"
            v-if="scope.row.orderStatus == '5' " 
          >退款回复</el-button>
          <el-button 
            size="mini"
            type="text"
            icon="el-icon-takeaway-box"
            @click="handleSendGoods(scope.row)"
            v-if="scope.row.orderStatus == '2'" 
          >发货</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-location-information"
            @click="handleLogisticsInfo(scope.row)"
            v-hasPermi="['system:role:edit']"
            v-if="parseInt(scope.row.orderStatus) >= 3" 
          >物流信息</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-takeaway-box"
            @click="handleGoodsChange(scope.row)"
            v-hasPermi="['system:role:edit']"
            v-if="parseInt(scope.row.orderStatus) == 7" 
          >退换货</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:role:edit']"
            v-if="parseInt(scope.row.orderStatus) >2 && parseInt(scope.row.orderStatus) !=8 && parseInt(scope.row.orderStatus) !=6" 
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:role:edit']"
            v-else
          >查看订单</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="checkGive(scope.row)"
            v-hasPermi="['system:role:edit']"
          >查看赠送内容</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:role:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
  </el-tooltip>
    <!-- <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[10, 200, 300, 400]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      align="right"
      :total="6">
    </el-pagination> -->

    <pagination
    v-show="total>0"
    :total="total"
    :page.sync="queryParams.pageNum"
    :limit.sync="queryParams.pageSize"
    @pagination="getList"/>

    <!-- 订单详情 -->
    <div v-if="showCard">
           <!-- 订单详情 -->
           <h2 align="center">订单明细</h2>
           <el-row :gutter="10" class="mb8" >
             <!-- <el-col :span="12"><el-button plain type="primary" size="mini" icon="el-icon-plus" @click="handleAddByOrder">新增</el-button></el-col> -->
           </el-row>
             <el-table :data="pisOrderList2" v-loading="orderloading">
               <el-table-column label="产品名称" prop="productName" align="center" width="150" ></el-table-column>
                 <el-table-column label="型号" align="center" prop="productType"></el-table-column>
                 <el-table-column label="单价" align="center" prop="productPrice"></el-table-column>
                 <el-table-column label="数量" align="center" prop="ordersNum"></el-table-column>   
                 <el-table-column label="金额" align="center" prop="ordersamount"></el-table-column>
                 <el-table-column label="时间" align="center" prop="outstockDate"></el-table-column>
                 <el-table-column label="操作" align="center">
                   <template slot-scope="scope"> 
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleOutGoods(scope.row)"
                      v-if="scope.row.orderStatus == '2'" 
                      >出库</el-button>
                         <!-- <el-button
                         size="mini"
                         type="text"
                         icon="el-icon-edit"
                         @click="handleUpdateByOrder(scope.row)"
                         >修改</el-button>
                         <el-button
                         size="mini"
                         type="text"
                         icon="el-icon-delete"
                         @click="handleDeleteByOrder(scope.row)"
                         >删除</el-button> -->
                     </template> 
                 </el-table-column>
             </el-table>
    </div>

    <!-- 查看赠送内容 -->
    <el-dialog :title="title" :visible.sync="giveopen" width="500px" append-to-body center>
      <el-table v-loading="loading" :data="giveList">
        <el-table-column label="产品名称" align="center" prop="productName"/>
        <el-table-column label="产品价值" align="center" prop="productPrice" />
        <el-table-column label="产品描述" align="center" prop="productDesc" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="giveopen=false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改用户和角色关联对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="会员昵称" prop="memberName">
          <el-select v-model="form.memberName" placeholder="会员昵称" clearable @change="memberChange" disabled>
            <el-option 
                v-for="item in memberList"
                :label="item.memberName" 
                :value="item.advMembersId"
                :key="item.advMembersId"/>
          </el-select>
        </el-form-item>
        <el-form-item label="会员账号" prop="memberAccount">
          <el-input v-model="form.memberAccount" placeholder="请输入会员账号" clearable disabled/>
        </el-form-item>
        <!-- <el-form-item label="产品名称" prop="productName">
          <el-select v-model="form.productName" placeholder="请输入产品名称" clearable @change="productChange">
            <el-option 
              v-for="item in productList"
              :label="item.productName" 
              :value="item.advProductsId"
              :key="item.advProductsId"/>
          </el-select>
        </el-form-item> -->
        <el-form-item label="订单号" prop="ordersno">
          <el-input v-model="form.ordersno" placeholder="请输入订单号" clearable disabled/>
        </el-form-item>
        <el-form-item v-if="form.orderStatus >2 &&form.orderStatus !=8 &&form.orderStatus!=6" label="物流公司" prop="wlcmpno">
          <el-select v-model="form.wlcmpno" placeholder="请选择物流公司" clearable>
            <el-option 
              v-for="dict in dict.type.logistics_company"
              :label="dict.label" 
              :value="dict.value"
              :key="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.orderStatus >2 &&form.orderStatus !=8 &&form.orderStatus!=6" label="物流单号" prop="delivesno">
          <el-input v-model="form.delivesno" placeholder="请输入新的物流单号" clearable />
        </el-form-item>
        <el-form-item label="订单总金额" prop="ordersamount">
          <el-input v-model="form.ordersamount" placeholder="请输入订单总金额" clearable disabled/>
        </el-form-item>
        <el-form-item label="订单日期" prop="advOrdersdate"> 
          <el-date-picker
            v-model="form.advOrdersdate"
            type="date"
            placeholder="请选择订单日期"
            style="width: 180px"
            value-format="yyyy-MM-dd"
            disabled/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 发货窗口 -->
    <el-dialog :title="title" :visible.sync="sendGoodsOpen" width="500px"  append-to-body center>
      <el-form ref="goodform" :model="goodform" :rules="rules" label-width="80px">
        <el-form-item label="订单号" prop="ordersno">
          <el-input v-model="goodform.ordersno" placeholder="请输入订单号" clearable disabled/>
        </el-form-item>
        <el-form-item label="物流公司" prop="wlcmpno">
          <el-select v-model="goodform.wlcmpno" placeholder="请选择物流公司" clearable>
            <el-option 
              v-for="dict in dict.type.logistics_company"
              :label="dict.label" 
              :value="dict.value"
              :key="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="物流单号" prop="delivesno">
          <el-input v-model="goodform.delivesno" placeholder="请输入物流单号" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="postSendGoods">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

        <!-- 物流信息窗口 -->
    <el-dialog :title="title" :visible.sync="logisticsinfo" width="500px"  append-to-body center>
      <el-form ref="logisticsinfodata" :model="logisticsinfodata" label-width="80px">
        <el-form-item label="快递单号">
          <el-input v-model="logisticsinfodata.nu" clearable disabled/>
        </el-form-item>
        <el-form-item label="物流公司">
          <el-select v-model="logisticsinfodata.com" clearable disabled>
            <el-option 
              v-for="dict in dict.type.logistics_company"
              :label="dict.label" 
              :value="dict.value"
              :key="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="物流信息">
          <el-scrollbar style="max-height: 300px; overflow-y: auto;">
            <div v-for="(item, index) in logisticsinfodata.data" :key="index" class="logistics-item">
              <p>时间: {{ item.time }}</p>
              <p>内容: {{ item.context }}</p>
              <p>位置: {{ item.location }}</p>
              <hr>
            </div>
          </el-scrollbar>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

        <!-- 退款窗口 -->
  <el-dialog :title="title" :visible.sync="payStatus" width="500px" append-to-body center>
    <div>
      <p>是否同意退款？</p>
    </div>
    <el-form  ref="payRefundData" :model="payRefundData" label-width="80px">
      <el-form-item label="拒绝理由"  v-if="notrefunds">
        <el-input v-model="payRefundData.remark" placeholder="退款则可无需理由" clearable/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="acceptRefund">同 意</el-button>
      <el-button type="danger" @click="rejectRefund">拒 绝</el-button>
    </div>
  </el-dialog>

       <!-- 换货窗口 -->
       <el-dialog :title="title" :visible.sync="goodsChangeOpen" width="500px" append-to-body center>
        <div>
          <p>是否同意换货？</p>
        </div>
        <el-form  ref="goodsChangeData" :model="goodsChangeData" :rules="rules" label-width="80px">
          <el-form-item label="订单号" prop="ordersno">
            <el-input v-model="goodsChangeData.ordersno" clearable disabled/>
          </el-form-item>
          <el-form-item label="物流公司" prop="wlcmpno" v-if="agreeGoodsChange">
            <el-select v-model="goodsChangeData.wlcmpno" placeholder="请选择物流公司" clearable>
              <el-option 
                v-for="dict in dict.type.logistics_company"
                :label="dict.label" 
                :value="dict.value"
                :key="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="物流单号" prop="delivesno" v-if="agreeGoodsChange">
            <el-input v-model="goodsChangeData.delivesno" placeholder="请输入物流单号" clearable />
          </el-form-item>
          <el-form-item label="拒绝理由" prop="remark"  v-if="notGoodsChange">
            <el-input v-model="goodsChangeData.remark" placeholder="退货则可无需理由" clearable/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="acceptChange">同 意</el-button>
          <el-button type="danger" @click="rejectChange">拒 绝</el-button>
        </div>
      </el-dialog>

  <!-- 出库窗口 -->
<el-dialog :title="title" :visible.sync="outgoodsOpen" width="500px" append-to-body center>
  <el-form ref="outgoodsData" :model="outgoodsData" :rules="rules" label-width="80px">
    <el-form-item label="产品名称" prop="productName">
      <el-input v-model="outgoodsData.ordersno" clearable disabled />
    </el-form-item>
    <el-form-item label="产品型号" prop="productModel">
      <el-input v-model="outgoodsData.productModel" clearable disabled />
    </el-form-item>
    <el-form-item label="产品数量" prop="ordersNum">
      <el-input v-model="outgoodsData.ordersNum" clearable disabled />
    </el-form-item>
    <el-form-item label="出库时间" prop="outstockDate">
      <el-date-picker 
        v-model="outgoodsData.outstockDate" 
        type="date" 
        placeholder="请选择出库时间" 
        clearable
        value-format="yyyy-MM-dd" 
      />
    </el-form-item>
    <el-form-item label="产品编号" prop="listDevicesno">
      <el-select
        v-model="outgoodsData.listDevicesno"
        no-data-text="无入库设备，请先完成设备入库"
        no-match-text="无入库设备，请先完成设备入库"
        multiple
        collapse-tags
        placeholder="请选择"
        :disabled="!outgoodsData.outstockDate">
        <el-option
          v-for="item in alldeviceno"
          :key="item.devicesno"
          :value="item.devicesno">
          {{ item.devicesno }}
        </el-option>
      </el-select>
    </el-form-item>
    
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button type="primary" @click="accpetOutGoods">确 定</el-button>
    <el-button @click="cancel">取 消</el-button>
  </div>
</el-dialog>

  </div>
</template>

<script>
  import { listProducts, addProducts, updateProducts, delProducts } from '@/api/server/products.js'
  import { listMembers, addMembers, updateMembers, delMembers } from '@/api/server/members.js'
  import { listOrders, addOrders, updateOrders, delOrders, 
        sendGoods, queryMaterialFlow, refundsByOrder, queryDeviceNo, outGoods, goodsChange} from '@/api/server/orders.js'
  import { listOrdersdetail, addOrdersdetail, updateOrdersdetail, 
           delOrdersdetail,queryOrderByMore, queryOrderByMoreTwo, queryOrderByMoreThree } from '@/api/server/ordersdetail.js'
  export default {
    dicts: ['adv_order_status','logistics_company'],
  data() {
    return {
      giveList: [], // 赠送内容列表
      giveopen: false, // 查看赠送内容是否打开
      selectedOrderId: null, // 用于存储被选中的订单ID
      myNum: 0,
      notGoodsChange: false,
      agreeGoodsChange: true,
      goodsChangeOpen: false,
      goodsChangeData: {},
      logisticsrequest: {
        com: "",
        num: "",
        phone: ""
      }, 
      selecteddeviceNo: {},
      alldeviceno: {},
      outgoodsOpen: false,
      outgoodsData: {},
      notrefunds: false,
      payStatus: false,
      payRefundData: {},
      logisticsinfodata: {},
      logisticsinfo: false,
      sendGoodsOpen: false, //发货窗口
      goodform: {},
      showCard: false, 
      orderloading: false, 
      pisOrderList: false,
      productList: [],
      memberList: [],
      productType: '1', // 设备产品
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productType: '1', // 设备产品
      },
      showSearch: true,
      single: false,
      multiple: false,
      loading: false,
      currentPage4: 1,
      roleList: [
      ],
      pisOrderList2: {},
      total: 0,
      title: "",
      open: false,
      form: {},
      rules: {
        memberName: [
          { required: true, message: "请输入会员昵称", trigger: "blur" }
        ],
        memberAccount: [
          { required: true, message: "请输入会员账号", trigger: "blur" }
        ],
        productName: [
          { required: true, message: "请输入产品名称", trigger: "blur" }
        ],
        ordersno: [
          { required: true, message: "请输入订单号", trigger: "blur" }
        ],
        ordersNum: [          
          { required: true, message: "请选择数量", trigger: "change" }
        ],
        advOrdersdate: [
          { required: true, message: "请选择订单日期", trigger: "change" }
        ],
        delivesno: [
          { required: true, message: "请输入物流单号", trigger: "blur" }
        ],
        wlcmpno: [
          { required: true, message: "请选择物流公司", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "请填写退款理由", trigger: "blur" }
        ],
        productModel: [
          { required: true, message: "请填写产品型号", trigger: "blur" }
        ],
        listDevicesno: [
          { required: true, message: "请先选择出库时间再选择设备编号", trigger: "change" }
        ],
        outstockDate: [
          { required: true, message: "请选择出库时间", trigger: "change" }
        ],
        ordersamount: [
          { required: true, message: "请输入订单总金额", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    this.getList();
    this.getProductList();
    this.getMemberList();
  },
  methods: {
    acceptChange(){
      if(this.title==='退换货'){
        console.log('同意退款--->', this.goodsChangeData);
        this.goodsChangeData.remark = null;
        this.notGoodsChange = false;
        this.agreeGoodsChange = true;
        this.$refs.goodsChangeData.validate((valid) => {
          if (valid) {
            goodsChange(this.goodsChangeData).then((response) => {
              this.getList();
              this.$message({
              type: 'success',
              message: '换货成功!',
            });
            this.goodsChangeOpen = false;
            this.agreeGoodsChange = false;
          }).catch(error => {
            console.error('系统错误', error);
            this.$message({
            type: 'error',
            message: '系统错误!',
            });
          });
        } else {
          this.$message({
            type: 'error',
            message: '表单验证失败!'
          });
        }
        })
      }
    },
    rejectChange(){
      if(this.title==='退换货'){
        this.notGoodsChange = true;
        this.agreeGoodsChange = false;
        if(this.goodsChangeData.remark != null){
          goodsChange(this.goodsChangeData).then((response) => {
          this.getList();
          this.$message({
            type: 'success',
            message: '拒绝成功!',
          });
          this.goodsChangeOpen = false;
          this.agreeGoodsChange = false;
        }).catch(error => {
          console.error('系统错误', error);
          this.$message({
            type: 'error',
            message: '系统错误!',
          });
        });
        } else {
          this.$message({
             type: 'error',
             message: '请填写拒绝退款理由!',
            });
        } 
      }
    },
    handleGoodsChange(row){
      this.title = '退换货';
      this.goodsChangeData = row;
      this.goodsChangeOpen = true;
      this.agreeGoodsChange = true;
    },
    accpetOutGoods(){
      if(this.title === '出库'){
        this.$refs.outgoodsData.validate((valid) => {
        if (valid) {
          if (this.outgoodsData.listDevicesno.length > this.outgoodsData.ordersNum){
            this.$message({
                type: 'error',
                message: '出库设备数量超出订单明细数量，已拦截出库',
            });
          }else{
            this.outgoodsData.myNum = this.myNum;
            outGoods(this.outgoodsData).then((response) => {
            if (this.outgoodsData.listDevicesno.length != this.outgoodsData.ordersNum){
                this.$message({
                type: 'sucess',
                message: '与订单明细产品设备数量不符，请注意补全，此次出库放行',
            });
            }else{
              this.$message({
              type: 'sucess',
              message: '出库成功',
              });
              this.outgoodsOpen = false;
            }
          }).catch(error => {
            console.error('系统错误', error);
            this.$message({
             type: 'error',
             message: '系统错误',
            });
          });
          }
        } else {
          this.$message({
            type: 'error',
            message: '表单验证失败!'
          });
        }
      })
    }
      
    },
    handleOutGoods(row){
      this.title = "出库";
      this.outgoodsOpen = true;
      this.outgoodsData = row;
      queryDeviceNo(row).then((response) => {
      console.log("queryDeviceNo response:", response); 
      this.alldeviceno = response.allDeviceNo;
      this.myNum = response.allDeviceNo.filter(item => item.selectflag == '1').length;
      console.log("myNum---->",this.myNum);
      this.outgoodsData.listDevicesno = response.allDeviceNo
        .filter(item => item.selectflag == '1')
        .map(item => item.devicesno);
      console.log("出库数组---->", response);
      })
    },
    // 选择用户发生改变的时候
    memberChange(advMembersId){
      this.memberList.filter((item) => {
        if(item.advMembersId === advMembersId) {
          this.form.memberAccount = item.memberAccount;
          this.form.advMembersId = item.advMembersId;
        }
      })
    },
    // 选择产品发生改变的时候
    productChange(advProductsId){
      this.productList.filter((item) => {
        if(item.advProductsId === advProductsId) {
          this.form.advProductsId = item.advProductsId;
          this.form.productName = item.productName;
          this.form.productModel = item.productModel;
          this.form.productDesc = item.productDesc;
          this.form.productPrice = item.productPrice;
          this.form.isSlive = item.isSlive;
          this.form.stocknum = item.stocknum;
        }
      })
    },
    // 查询到所有的产品
    getProductList(){
      listProducts(this.queryParams).then((response) => {
        this.productList = response.rows
        
      })
    },
    // 查询所有会员
    getMemberList() {
      listMembers().then((response) => {
        this.memberList = response.rows
      })
    },
    handleQuery() {
      this.getList();
    },
    resetQuery() {},
    handleExport() {
      this.download('/system/ordersdetail/export', {
        ...this.queryParams
      }, `硬件订单列表_${new Date().getTime()}.xlsx`)
    },
    getList() {
      listOrdersdetail(this.queryParams).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        console.log('getList()--->',response.rows);
      })
    },
    handleSelectionChange() {},
    cancel() {
        this.open = false;
        this.sendGoodsOpen = false;
        this.logisticsinfo = false;
        this.outgoodsOpen = false;
        this.reset();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.advOrdersId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    checkGive(row) {
      this.title = `查看内容列表(赠送订单编号${row.ordersno})`;
      this.giveopen = true;
      queryOrderByMoreThree(row.advOrdersId).then((response) => {
        this.giveList = response.data;
        console.log(response, "赠送内容", row.advOrdersId);
        if(response.statusCode == '404') {
          this.$message({
            type: 'warning',
            message: response.message
          });
        }
      });
    },
    handleUpdate(row) {
      this.reset();
      this.form = row;
      if(row.orderStatus>2&&row.orderStatus!=6&&row.orderStatus!=8){
        this.title = "修改订单";
      }else{
        this.title = "查看订单";
      }
      console.log("点击修改查看log-->",row);   //查看数据
      this.open = true;
      
      
    },
    handleRefund(row){
      this.payRefundData = row;
      this.title = "退款确认";
      this.payStatus = true;
    },
    rejectRefund() {
      // 处理拒绝退款逻辑
      if (this.title === '退款确认') {
        console.log('拒绝退款--->', this.payRefundData);
        this.notrefunds = true;
        if(this.payRefundData.remark !=null){
            refundsByOrder(this.payRefundData).then((response) => {
            this.getList();
            this.$message({
              type: 'success',
              message: '已经驳回退款!',
            });
            this.payStatus = false;
            this.notrefunds = false;
          }).catch(error => {
            console.error('系统错误', error);
            this.$message({
             type: 'error',
             message: '系统错误',
            });
          });
        } else {
          this.$message({
             type: 'error',
             message: '请填写拒绝退款理由!',
            });
        } 
      }
    },
    acceptRefund() {
      if (this.title === '退款确认') {
        console.log('同意退款--->', this.payRefundData);
        this.payRefundData.remark = null;
        refundsByOrder(this.payRefundData).then((response) => {
          this.getList();
          this.$message({
            type: 'success',
            message: '退款成功!',
          });
          this.payStatus = false;
        }).catch(error => {
          console.error('系统错误', error);
          this.$message({
            type: 'error',
            message: '系统错误!',
          });
        });
      }
    },
    handleSendGoods(row){
      this.goodform = row;
      this.sendGoodsOpen = true;
      this.title = "发货";
    },
    postSendGoods(){
      console.log("发货-->",this.goodform);
      this.$refs.goodform.validate((valid) => {
        if (valid) {
          if(this.title === '发货') {
            sendGoods(this.goodform).then((response) => {
              this.$message({
                type: 'success',
                message: '发货成功!'
              });
              this.sendGoodsOpen = false;
            })
          }
          this.getList();
        } else {
          this.$message({
            type: 'error',
            message: '表单验证失败!'
          });
        }
      });
    },
    handleLogisticsInfo(row){
      this.logisticsrequest.num = row.delivesno;
      this.logisticsrequest.com = row.wlcmpno;
      this.logisticsinfo = true;
      this.title = "物流信息";
      queryMaterialFlow(this.logisticsrequest).then((response) => {
        console.log("Message----->",response);
        this.logisticsinfodata = response.data;
        this.$message({
          type: 'success',
          message: '查询成功!'
        });
      })
    },
    handleAddByOrder(){

    },
    rowClassName({ row }) {
    return row.advOrdersId === this.selectedOrderId ? 'selected-row' : ''; // 判断是否选中
    },
    showTab(row) {
      this.orderloading = true;
      this.selectedOrderId = row.advOrdersId; // 存储选中行的订单ID
      queryOrderByMore(row.advOrdersId).then((response) => {
          this.showCard = true;
          this.orderloading = false;
          this.commloading = false;
          this.pisOrderList2 = response.rows;
          console.log('详情信息--->',response);
      });
    },
    reset() {
      this.form = {
        memberName: "",
        memberAccount: "",
        productName: "",
        status: "",
        isAnchor: ""
      }
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除该主播, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        row.orderStatus = 4;
        updateOrders(row).then((response) => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getList();
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if(this.title === '添加订单') {
            this.form.balFlag = '0';
            addOrders(this.form).then((response) => {
              this.getList();
              this.$message({
                type: 'success',
                message: '提交成功!'
              });
              this.open = false;
            })
          }
          if(this.title === '修改订单') {
            console.log("修改订单---->",this.form)
            updateOrders(this.form).then((response) => {
              this.getList();
              this.$message({
                type: 'success',
                message: '提交成功!'
              });
              this.open = false;
            })
          }
        } else {
          this.$message({
            type: 'error',
            message: '表单验证失败!'
          });
        }
      })
    },
    handleSolid(row) {
      this.$confirm('此操作将永久拉黑该主播, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '拉黑成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消拉黑'
        });
      });
    },
    handleStop(row) {
      this.$confirm('此操作将永久禁用该主播, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '禁用成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消禁用'
        });
      });
    },
    
  }
}
</script>

<style>
.logistics-container {
  overflow: auto;
}
.logistics-item {
  margin-bottom: 15px;
}
.selected-row {
  background-color: #f0f9eb !important; /* 选中行的背景颜色 */
}
</style>

